package com.gitee.andy.zpush.client;

import java.util.UUID;

import com.gitee.andy.zpush.entity.ChatMsg;
import com.gitee.andy.zpush.kernel.Session;
import com.gitee.andy.zpush.kernel.TcpClient;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;

public class ZpushTestClient {
	public static void main(String[] args) {
		TcpClient tcpClient = new TcpClient(1, new ChannelInitializer<SocketChannel>() {

			@Override
			protected void initChannel(SocketChannel ch) throws Exception {
				ch.pipeline().addLast(
						new ObjectDecoder(1024 * 1024 * 8,
								ClassResolvers.softCachingConcurrentResolver(this.getClass().getClassLoader())),
						new ObjectEncoder(), new EchoClientHandler());
			}
		});
		Session session = tcpClient.connect("127.0.0.1", 8007);

		session.write(new ChatMsg(UUID.randomUUID().toString(), UUID.randomUUID().toString()));

		try {
			Thread.sleep(10 * 1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		tcpClient.shutdown();
	}
}
